perm filename GROPER.RLS[225,JMC] blob
sn#005365 filedate 1971-01-29 generic text, type T, neo UTF8
00050 OFF ECHO;
00075
00100 COMMENT These functions are concerned with generating the
00200 permutations of a list of numbers and in generating the
00300 positive and negative groups of permutations on a list of
00400 numbers.;
00500
00600 COMMENT isdesc u is true if the list of numbers u
00700 is in descending order.;
00800
00900 ISDESC U ← NULL U OR NULL CDR U OR
01000 (CAR U > CADR U AND ISDESC CDR U);
01100
01200 COMMENT next u is the permutation following u in order.;
01300
01400 NEXT U ←
01450 IF NULL CDDR U THEN LIST(CADR U,CAR U)
01500 ELSE IF ISDESC CDR U THEN
01600 (LAMBDA Z; Z . SORT(CAR U . DEL(Z,CDR U)))
01700 NEXTB(CAR U,CDR U)
01800 ELSE CAR U . NEXT CDR U;
01820
01840 NEXTB(X,U) ←
01860 IF CAR U < X THEN NEXTB(X,CDR U)
01880 ELSE NEXTC(X,CAR U,CDR U);
01900
02000 NEXTC(X,Y,U) ←
02100 IF NULL U THEN Y
02200 ELSE IF CAR U < X OR CAR U > Y THEN NEXTC(X,Y,CDR U)
02300 ELSE NEXTC(X,CAR U,CDR U);
02400 DEL(X,U) ←
02500 IF NULL U THEN NIL
02600 ELSE IF X = CAR U THEN CDR U
02700 ELSE CAR U . DEL(X,CDR U);